home *** CD-ROM | disk | FTP | other *** search
- Program Mouse_Draw;
-
- (* *)
- (* An Example Program for TheMouse *)
- (* A Turbo Pascal Mouse Unit by Kevin Kwast *)
- (* *)
-
- Uses Graph, Crt, TMouse5; {Change to TMouse4 if using Turbo Pascal 4}
-
- Type
- gCurs = Array[1..32] of Word;
- gCursRec = Record
- Image: gCurs;
- HotX, HotY: Word;
- End;
-
- Const
- CrayonImage: GCurs = ($FFF1, $FFE0, $FFC0, $FF80,
- $F300, $FE01, $FC03, $F807,
- $F00F, $E01F, $C03F, $807F,
- $00FF, $01FF, $03FF, $87FF,
- $0000, $000E, $001F, $0037,
- $0066, $00CC, $0198, $0330,
- $0660, $0CC0, $1980, $3300,
- $6600, $6C00, $7800, $2000);
-
- (*
- The field used in the graphics cursor mask is defined as follows:
-
- The mask must be an array of 32 words, the first 16 are the "screen mask"
- and the second 16 words are the "cursor mask". The device driver ANDs the
- screen mask with the 16 x 16 bit screen area where the cursor is being
- displayed, and then XORs the cursor mask with that result, producing these
- results:
-
- Screen Mask Bit Cursor Mask Bit Display Bit
-
- 0 0 0
- 0 1 1
- 1 0 Unchanged
- 1 1 Inverted
-
- Each mask is a 16 x 16 bit data area. It can be seen easier by drawing out
- the bits for each mask. The crayon used in this program looks like this:
-
- Screen Mask Cursor Mask
-
- 1111111111110001 0000000000000000
- 1111111111100000 0000000000001110
- 1111111111000000 0000000000011111
- 1111111110000000 0000000000110111
- 1111111100000000 0000000001100110
- 1111111000000001 0000000011001100
- 1111110000000011 0000000110011000
- 1111100000000111 0000001100110000
- 1111000000001111 0000011001100000
- 1110000000011111 0000110011000000
- 1100000000111111 0001100110000000
- 1000000001111111 0011001100000000
- 0000000011111111 0110011000000000
- 0000000111111111 0110110000000000
- 0000001111111111 0111100000000000
- 1000011111111111 0010000000000000
-
- Notice that the screen mask is the size of the cursor mask and a little
- larger for the black outline effect.
-
- *)
-
- Var
- Crayon : GCursRec;
-
- Done: Boolean;
-
- gd, gm: integer;
-
- tmInit: TheMouseInitType;
- tmInfo: TheMouseInfoType;
- tmEvent: TheMouseEventType;
-
- (*** Here is the event handler.. ***)
-
- {$F+} { Far Calls for Event Handler }
-
- Procedure Event(Flags, CS, AX, BX, CX, DX, SI, DI, DS, ES, BP: Word);
-
- {This will be called by the mouse driver, and must have this format}
- Interrupt;
-
- Begin
- tmEvent.EventMask := AX;
- tmEvent.ButtonStatus := BX;
- tmEvent.Column := CX;
- tmEvent.Row := DX;
-
- Inline ( { exit for far return to mouse device driver }
- $8B/$E5/ { Mov SP,BP }
- $5D/ { Pop BP }
- $07/ { Pop ES }
- $1F/ { Pop DS }
- $5F/ { Pop DI }
- $5E/ { Pop SI }
- $5A/ { Pop DX }
- $59/ { Pop CX }
- $5B/ { Pop BX }
- $58/ { Pop AX }
- $CB ); { RetF }
- End;
-
- {$F-}
-
- Procedure TopMessage(S: String);
- Var X, Y: Word;
- Begin
- SetViewPort(0,0,GetMaxX,28,False);
- ClearViewPort;
- SetViewPort(0,0,GetMaxX,GetMaxY,False);
-
- SetTextStyle(DefaultFont, HorizDir, 1);
- X:=(GetMaxX - TextWidth(S)) div 2;
- Y:=13 - (TextHeight(S) div 2);
- OutTextXY(X,Y,S);
- Line(0,27,GetMaxX,27);
- End;
-
- Procedure BottomMessage(S: String);
- Var X, Y: Word;
- Begin
- SetViewPort(0,GetMaxY-17,GetMaxX,GetMaxY,False);
- ClearViewPort;
- SetViewPort(0,0,GetMaxX,GetMaxY,False);
-
- SetTextStyle(DefaultFont, HorizDir, 1);
- X:=(GetMaxX - TextWidth(S)) div 2;
- Y:=(GetMaxY - 9) - (TextHeight(S) div 2);
- OutTextXY(X,Y,S);
- Line(0,GetMaxY-18,GetMaxX,GetMaxY-18);
- End;
-
-
- Begin
- With Crayon do
- Begin
- Image:=CrayonImage;
- HotX:=3;
- HotY:=16;
- End;
-
- tmReset(tmInit);
- If NOT tmInit.Exists then Begin
- WriteLn('Mouse driver not found.');
- Halt;
- End;
-
- Gd:=CGA; Gm:=CGAHi;
- InitGraph(Gd, Gm, 'C:\TURBO\BGI'); {Put the location of your BGI files}
- If GraphResult <> grOk then Begin
- WriteLn('Error loading graphics system.');
- Halt;
- End;
-
- TopMessage('MouseDraw example for TheMouse');
- BottomMessage('Hold Down Left: Draw Right: Command Mode');
-
- tmColRange(2,GetMaxX-4);
- tmRowRange(30,GetMaxY-20);
- tmGraphCursor(Crayon.HotX, Crayon.HotY, Seg(Crayon.Image), Ofs(Crayon.Image));
- tmCursor(True);
-
- tmTask($55, Seg(Event), Ofs(Event)); {Set up Event handler}
-
- (* Task will trigger on movement, or on any button release *)
-
- Done:=False;
-
- Repeat
-
- tmEvent.EventMask:=0; { Make sure it doesn't get previous results }
- REPEAT UNTIL (tmEvent.EventMask <> 0);
- CASE tmEvent.EventMask OF
- $0001: Begin {any motion}
- If tmEvent.buttonstatus = 1 then {Left Button Down}
- Begin
- tmCursor(False); {Be sure cursor is off here}
- PutPixel(tmEvent.Column, tmEvent.Row, 1);
- tmCursor(True); {Now turn it back on}
- End;
- End;
- $0010: Begin {right button release with no movement}
- BottomMessage('Now: Left: Quit Middle: Abort Right: Clear ');
- tmPos(tmInfo); {Save cursor location}
- tmCursor(False); {Turn cursor off}
- Repeat
- tmEvent.EventMask:=0;
- REPEAT UNTIL tmEvent.EventMask <> 0;
- tmEvent.EventMask:=tmEvent.EventMask and $54;
- CASE tmEvent.EventMask OF
- $04: Done:=True;
- $10: Begin
- tmCursor(False);
- SetViewPort(0, 30, GetMaxX, GetMaxY-19,False);
- ClearViewPort;
- tmCursor(True);
- End;
- $40: ; {Do Nothing}
- ELSE tmEvent.EventMask:=0;
- END;
- Until (tmEvent.EventMask <> 0);
- tmMoveTo(tmInfo.Column, tmInfo.Row);
- tmCursor(True); {Put Cursor Back}
- BottomMessage('Hold Down Left: Draw Right: Command Mode');
- End;
- END;
-
- Until Done;
-
- tmReset(tmInit);
- CloseGraph;
- End.